/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SimpleCommentPanel.java
 *
 * Created on 22/Out/2012, 10:46:36
 */
package chatclient;

import com.sd.chat.Comment;
import javax.swing.JOptionPane;
import org.jdesktop.application.Action;

/**
 *
 * @author Old
 */
public class SimpleCommentPanel extends javax.swing.JPanel {

    private Comment comm;
    private ChatSDClientView pai;
    private boolean isMine;

    /** Creates new form SimpleCommentPanel */
    public SimpleCommentPanel(ChatSDClientView pai, Comment comment, boolean isMine) {
        initComponents();
        this.pai = pai;
        this.isMine = isMine;
        this.comm = comment;
        posterName.setText(comment.getUser().getNome());
        commentText.setText(comment.getText());
        if (!isMine) {
            butEliminar.setVisible(isMine);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        posterName = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        commentText = new javax.swing.JTextArea();
        butEliminar = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chatclient.ChatSDClientApp.class).getContext().getResourceMap(SimpleCommentPanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        setMaximumSize(new java.awt.Dimension(650, 32767));
        setMinimumSize(new java.awt.Dimension(650, 80));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(650, 80));

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        posterName.setText(resourceMap.getString("posterName.text")); // NOI18N
        posterName.setName("posterName"); // NOI18N

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setFocusable(false);
        jScrollPane1.setMaximumSize(new java.awt.Dimension(595, 32767));
        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(595, 96));

        commentText.setBackground(resourceMap.getColor("commentText.background")); // NOI18N
        commentText.setColumns(20);
        commentText.setRows(5);
        commentText.setName("commentText"); // NOI18N
        jScrollPane1.setViewportView(commentText);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(chatclient.ChatSDClientApp.class).getContext().getActionMap(SimpleCommentPanel.class, this);
        butEliminar.setAction(actionMap.get("clickedEliminar")); // NOI18N
        butEliminar.setText(resourceMap.getString("butEliminar.text")); // NOI18N
        butEliminar.setName("butEliminar"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(posterName))
                    .addComponent(butEliminar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(posterName))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                        .addComponent(butEliminar)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void clickedEliminar() {
        Object[] options = {"Sim",
            "Não"};
        int n = JOptionPane.showOptionDialog(this,
                "Este comentário será eliminado, dejesa continuar?",
                "Eliminar",
                JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE,
                null, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default button title
        if (n == 0) {
            pai.eliminateSubmit(comm.getId(), false);
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butEliminar;
    private javax.swing.JTextArea commentText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel posterName;
    // End of variables declaration//GEN-END:variables
}
